package com.demo.study.algorithm.leetcode;

import org.junit.Test;

/**
 * LT1342
 * <a href="https://leetcode.cn/problems/number-of-steps-to-reduce-a-number-to-zero/description/">将数字变成 0 的操作次数</a>
 *
 * @author Baymax
 * @since 2024-11-15
 */
public class LT1342 {
    @Test
    public void run() {
        System.out.println(numberOfSteps(14));
    }

    public int numberOfSteps(int num) {
        int steps = 0;
        while (num != 0) {
            if (num % 2 == 0) {
                num = num / 2;
            } else {
                num -= 1;
            }
            steps++;
        }
        return steps;
    }

}
